jQuery(document).foundation();

var delayAutoComplete;
function elementNeed() {
	if ($('#label_wrapper').is(':visible')) {
		return "autocomplete_box";
	} else {
		return "mobile_autocomplete_box";
	}
}
$(document).ready(function() {
	$('#search_box').keyup(function() {
		var obj = $(this);
		if (obj.val() != '') {
			$('#cancel_icon').removeClass('hide');
			clearTimeout(delayAutoComplete);
			delayAutoComplete = setTimeout(function() {
				jQuery('#content #' + elementNeed()).css({'left': obj.position().left + (obj.parent().attr('id') == "search_page_box" ? 0: 110), 'top':obj.position().top + obj.height() + 20}).slideDown();
			}, 1000);
		} else {
			$('#cancel_icon').addClass('hide');
			clearTimeout(delayAutoComplete);
			jQuery('#content #' + elementNeed()).slideUp();
		}
	});
	$('#cancel_icon').click(function() {
		clearTimeout(delayAutoComplete);
		jQuery('#content #' + elementNeed()).slideUp();
		$('#search_box').val('');
		$('#cancel_icon').addClass('hide');
	});
	$('#mobile_autocomplete_close_box').click(function() {
		$('#cancel_icon').click();
	});
});